﻿using System.Collections.Generic;
using System.Web.Mvc;
using BlueLotus7.Eden.Web.ChinaZipSearchWebService;
using BlueLotus7.Eden.Web.IpAddressSearchWebService;
using BlueLotus7.Eden.Web.ChinaMobileCodeWebService;

namespace BlueLotus7.ThirdPartyService
{
    public static class ThirdPartyServiceCluster
    {
        #region IpAddressLocationService

        /// <summary>
        /// Finds locations by IP Address.
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <returns></returns>
        public static string FindIpAddressLocation(string ipAddress)
        {
            string info = string.Empty;

            using (IpAddressSearchWebServiceSoapClient client = new IpAddressSearchWebServiceSoapClient())
            {
                string[] result = client.getCountryCityByIp(ipAddress);
                if (result != null && result.Length >= 2)
                {
                    info = result[1];
                }
            }

            return info;
        }

        #endregion

        #region ChinaZipSearchService

        public static string GetAddressByZipCode(string zipCode)
        {
            string info = string.Empty;

            using (ChinaZipSearchWebServiceSoapClient client = new ChinaZipSearchWebServiceSoapClient())
            {
                var result = client.getAddressByZipCode(zipCode, null);
                if (result != null)
                {

                }
            }

            return info;
        }

        public static List<string> GetSupportProvince()
        {
            List<string> result = new List<string>();

            using (ChinaZipSearchWebServiceSoapClient client = new ChinaZipSearchWebServiceSoapClient())
            {
                result = new List<string>(client.getSupportProvince());
            }

            return result;
        }

        public static List<string> QueryZipCodeByAddress(string theProvinceName, string theCityName, string theAddress)
        {
            List<string> result = new List<string>();

            using (ChinaZipSearchWebServiceSoapClient client = new ChinaZipSearchWebServiceSoapClient())
            {
                var data = client.getZipCodeByAddress(theProvinceName, theCityName, theAddress, null);

            }

            return result;
        }

        #endregion

        #region ChinaMobileCodeWebService

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mobileNumber">At least the first 7 digitals</param>
        /// <returns></returns>
        public static MobileInfo GetMobileNumberInfo(string mobileNumber)
        {
            MobileInfo info = null;

            using (MobileCodeWSSoapClient client = new MobileCodeWSSoapClient())
            {
                string result = client.getMobileCodeInfo(mobileNumber, null);
                string[] results = result.Split(' ');
                info = new MobileInfo();
                info.Province = results[0];
                info.City = results[1];
                info.Type = results[2];
            }

            return info;
        }

        #endregion
    }
}
